package com.dream.service.recommender.base.compare;

import com.dream.service.recommender.domain.response.RecommenderItem;

import java.util.Comparator;

/**
 * Created by zhiji on 2016/04/25.
 */
public class WeightComparator implements Comparator<RecommenderItem> {

    private boolean reverse;

    public WeightComparator(){

    }
    public WeightComparator(boolean reverse){
            setReverse(reverse);
    }

    public boolean isReverse() {
        return reverse;
    }

    public void setReverse(boolean reverse) {
        this.reverse = reverse;
    }

    @Override
    public int compare(RecommenderItem o1, RecommenderItem o2) {
        if (o1.getW() == o2.getW()) {
            return 0;
        }
        return o2.getW() - o1.getW() > 0 ? 1 : -1;
    }
}
